<?php
/**
 * @author shuang
 * @date 2016-10-24 16:41:53
 */
$this->registerCssFile("/css/validate.css");
$this->registerCssFile("/js/ui-dialog.css");
$this->registerCssFile("/js/plugins/fileinput/css/fileinput.css");
$this->registerJsFile("/js/plugins/fileinput/fileinput.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile("/js/plugins/fileinput/fileinput_locale_zh.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile("/js/jquery.form.min.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile("/js/Validform_v5.3.2_min.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile("/js/WdatePicker.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile("/js/dialog-plus-min.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile("/js/plupload.full.min.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile("/js/common.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile('/js/task.js', [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);

use \yii\helpers\Url;
use yii\helpers\ArrayHelper;
use common\components\MTools;
use yii\helpers\Html;

$singleData = MTools::dictDropdownDesc("task_single_num");
$sampleData = MTools::dictDropdownDesc("task_sample_num");
$this->registerJs('AjaxInitForm("#addForm", "#btnSubmit", 1);');
$this->registerJs('task.upImgbind({updiv:$(\'#pickfiles\'),url:"",divimg:$(\'#divimg\'),imgfile:$(\'#imgfile\')});task.addStep();');
echo $this->render("//layouts/breadcrumb", ["url" => Url::toRoute(["update", "id" => $model->id]), "title" => "编辑任务"]);
$stepdata = $model->step ? \yii\helpers\Json::decode($model->step) : [];
?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12 well ibox float-e-margins">
            <div class="ibox-title">编辑任务</div>
            <div class="well-content ibox-content">
                <form name="addForm" method="post" action="<?php echo Url::toRoute(["update", "id" => $model->id]) ?>" id="addForm" class="form-horizontal form-bordered" url="<?php echo Url::toRoute(["update", "id" => $model->id]) ?>">
                    <div class="panel-body panel-body-nopadding">
                        <input type="hidden" name="hidid" id="hidid" value="<?php echo $id; ?>" />
                        <div class="control-group">
                            <label class="control-label">功能选择</label>
                            <div class="controls">
                                <div class="btn-group">
                                    <a class="btn btn-default" href="<?php echo Url::toRoute(["zhuijia", "id" => $id]); ?>">追加</a>
                                    <a class="btn btn-default" href="<?php echo Url::toRoute(["xiansu", "id" => $id]); ?>">限速</a>
                                    <a class="btn btn-primary" href="<?php echo Url::toRoute(["update", "id" => $id]); ?>">修改描述</a> 
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">任务名称</label>
                        <div class="controls text">
                            <?php echo $model->title; ?>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">任务类型</label>
                        <div class="controls">
                            <ul class="wizard nav nav-task-type">
                                <li class="active">
                                    <a href="javascript:;" data-toggle="tab" data-id="<?php echo $model->type; ?>"><?php echo ArrayHelper::getValue(ArrayHelper::map(MTools::dictDropdown("task_type"), "id", "name"), $model->type); ?></a>
                                </li>
                            </ul>
                            <input type="hidden" name="type" value="<?php echo $model->type; ?>"/>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">任务单价</label>
                        <div class="controls">
                            <ul class="wizard nav nav-task-price">
                                <li class="active"><a href="javascript:;" data-toggle="tab" ><?php echo MTools::getTaskPrice($model->task_price_id); ?></a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">任务名称</label>
                        <div class="controls">
                            <input class="span6"  type="text" name="title" value="<?php echo $model->title; ?>" datatype="*6-60" errormsg="长度在6-60位之间" nullmsg="请输入任务标题" sucmsg=" "   />
                        </div>
                    </div>
                    <div class="control-group">
                        <label  class="control-label">投票地址</label>
                        <div class="controls">
                            <input class="span6"  type="text" id="tpurl" name="vote_address" value="<?php echo $model->vote_address; ?>" nullmsg="请输入投票地址" sucmsg=" " />
                        </div>
                    </div>
                    <!--                    <div class="control-group">
                                            <label class="control-label">简介</label>
                                            <div class="controls">
                                                <textarea class="span6" id="jianjie" name="note" rows="7" placeholder="公众号或链接地址可以写到上面，方便会员复制，提高任务效率，请在这里写清楚任务流程和截图标准！投票内容描述越清晰，做的速度越快！" ><?php echo $model->note; ?></textarea>
                                            </div>
                                        </div>-->
                    <div class="control-group">
                        <label class="control-label">所需截图</label>
                        <div class="controls">
                            <select name="sample_figure_count" class="form-control mb15 span3">
                                <?php foreach ($sampleData as $item): ?>
                                    <option value="<?php echo $item["id"]; ?>" <?php echo $item["id"] == $model->sample_figure_count ? "selected" : null; ?>><?php echo $item["name"]; ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">样图</label>
                        <div class="controls">
                            请确保样图清晰准确，将直接影响到做任务的效率和质量<br/>
                            <input id="qrpickfiles" name="WB_Task[sample_figure]" type="file" multiple class="btn btn-success">
                            <?php if ($model->sample_figure): ?>
                                <div class="col-sm-6">
                                    <?php echo Html::tag('img', '', ['src' => MTools::Qiniu480($model->sample_figure), 'class' => 'img-thumbnail']); ?>
                                    <?php echo Html::hiddenInput("sample_figure", $model->sample_figure); ?>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <!--                    <div class="control-group">
                                            <label class=" control-label">二维码</label>
                                            <div class="controls">
                                                如不需要扫码，请不要上传，如需修改二维码，在任务列表点功能按钮修改<br/>
                                                <input id="qrpickfilesqrcode" name="WB_Task[qrcode]" type="file" multiple class="btn btn-success">
                    <?php if ($model->qrcode): ?>
                                                                                        <div class="col-sm-6">
                        <?php //echo Html::tag('img', '', ['src' => MTools::Qiniunow480($model->qrcode), 'class' => 'img-thumbnail']); ?>
                        <?php //echo Html::hiddenInput("qrcode", $model->qrcode); ?>
                                                                                        </div>
                    <?php endif; ?>
                                            </div>
                                        </div>-->
                    <!--                    <div class="control-group">
                                            <label  class="control-label">备注</label>
                                            <div class="controls">
                                                <textarea class="span6" id="beizhu" name="description" rows="7" placeholder="仅发布者可见，便于做记录。" ><?php echo $model->description; ?></textarea>
                                            </div>
                                        </div>-->
                    <!--                     <div class="control-group">
                                            <label  class="control-label">注意事项</label>
                                            <div class="controls">
                                                <textarea class="span6" id="beizhu" name="considerations" rows="7" placeholder="注意事项" ><?php echo $model->considerations; ?></textarea>
                                            </div>
                                        </div>-->
                    <div class="control-group clonediv" style="display: none;">
                        <label  class="control-label">任务步骤</label>
                        <div class="controls">
                            <textarea class="span6" name="step[]" rows="7" placeholder="" ></textarea>
                            <div class="mb15"></div>
                            <input name="stepfile[]" type="file" multiple class="btn btn-success">
                        </div>
                    </div>
                    <?php if ($stepdata): ?>
                        <?php foreach ($stepdata as $key => $item): ?>
                            <div class="control-group stepclone">
                                <label  class="control-label">任务步骤</label>
                                <div class="controls">
                                    <textarea class="span6" name="step<?php echo $key; ?>" rows="7" placeholder="" ><?php echo $item["step"]; ?></textarea>
                                    <div class="mb15"></div>
                                    <input name="stepfile<?php echo $key; ?>[]" type="file" multiple class="btn btn-success stepimage<?php echo $key; ?>">
                                    <?php if ($item['stepfile']): $arr_stepfile = explode(",", $item['stepfile']) ?>
                                        <div class="col-sm-6">
                                            <?php foreach ($arr_stepfile as $val): ?>
                                                <?php echo Html::tag('img', '', ['src' => MTools::Qiniu480($val), 'class' => 'img-thumbnail']); ?>
                                            <?php endforeach; ?>
                                            <?php echo Html::hiddenInput("stepfile" . ($key + 1), $item['stepfile']); ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php $this->registerJs('$(".stepimage' . ($key) . '").fileinput({
                showCaption: false,
                browseClass: "btn orange",
                browseLabel: "添加步骤图片",
                browseIcon: "<i class=\"glyphicon glyphicon-picture\"></i> ",
                showRemove: false,
                showUpload: false
            });'); ?>
                        <?php endforeach; ?>
                    <?php endif; ?>
                    <div class="control-group">
                        <label class="control-label">&nbsp;&nbsp;</label>
                        <input type="hidden" name="stepcount" value="<?php echo count($stepdata); ?>" />
                        <div class="controls">
                            <a class="btn addstep">添加步骤</a>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"></label>
                        <div class="controls">
                            <input name="btnSubmit" id="btnSubmit" type="submit" class=" btn lightblue span2" value="提  交" />
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
